<!DOCTYPE html>
<html>
#{include file="header.html"}#
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox-content">
        <form class="form-horizontal" method="post" action="#">
            <input type="hidden" name="contract_id" value="#{$contract_id}#">
            <div class="form-group">
                <label class="col-sm-2 control-label">文件名称</label>
                <div class="col-sm-10">
                    <input name="name" class="form-control" type="text" placeholder="输入文件名称" required/>
                    <span class="help-block m-b-none"></span></div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">附件图片</label>
                <div class="col-sm-10">
                    <div class="imgupload">
                        <div id="imglist" class="imglist"></div>
                        <div class="actbtn"><img src="#{$smarty.const.APP}#/View/template/img/webuploader.png"  onClick="javascript:imgupload('imglist');"></div>
                    </div>
                    <span class="help-block m-b-none"></span>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-8">
                    <button class="btn btn-w-m btn-info save-form" type="button">保存数据</button>
                </div>
            </div>
        </form>
    </div>
</div>
<!-- 自定义js -->
<script src="#{$smarty.const.APP}#/View/template/js/content.js?v=1.0.0"></script>
<script>
    //iframe层
    function imgupload(imgs_id) {
        layer.open({
            type: 2,
            title: '图片上传',
            shadeClose: true,
            fixed: false, //不固定
            area: ['90%', '90%'],
            content: '#{$smarty.const.ACT}#/Upload/upload_img/imgs_id/' + imgs_id //iframe的url
        });
    }

    $(document).ready(function () {

        //绑定删除图片
        $("body").on("click", ".imgupload_remove_img", function () {
            var li = $(this).parent().parent();
            var imgfile = $(this).attr('data-url');
            $.ajax({
                type: "GET",
                url: "#{$smarty.const.ACT}#/Upload/upload_img_remove/",
                data: {imgfile: imgfile},
                dataType: "json",
                success: function (data) {
                    if (data.rtnstatus == 'success') {
                        li.remove();
                    } else {
                        layer.msg(data.message, {icon: 5});
                    }
                }
            });
            //li.remove();
        });

        //数据保存
        $("body").on("click", ".save-form", function () {
            FormData = $("form").serialize();
            $.ajax({
                type: "POST",
                url: "#{$smarty.const.ACT}#/crm/SalContractFile/sal_contract_file_add/",
                data: FormData,
                dataType: "json",
                success: function (data) {
                    if (data.statusCode == '200') {
                        layer.msg('操作成功', {icon: 1});
                    }
                },
                complete: function () {
                    setTimeout(function () {
                        //关闭窗口
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                    }, 800);
                },
            });
        });
    });
</script>
</body>
</html>